class AttendencesController < ApplicationController
  # GET /attendences
  # GET /attendences.xml
  def index
    @attendences = Attendence.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @attendences }
    end
  end

  # GET /attendences/1
  # GET /attendences/1.xml
  def show
    @attendence = Attendence.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @attendence }
    end
  end

  # GET /attendences/new
  # GET /attendences/new.xml
  def new
    @attendence = Attendence.new
    @students = Student.all.collect {|x| [x.name,x.id]}
    @teachers = Teacher.all.collect {|x| [x.name,x.id]}
    @courses = Course.all.collect {|x| [x.name,x.id]}
    @rooms = Room.all.collect {|x| [x.name,x.id]}
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @attendence }
    end
  end

  # GET /attendences/1/edit
  def edit
    @attendence = Attendence.find(params[:id])
    @students = Student.all.collect {|x| [x.name,x.id]}
    @teachers = Teacher.all.collect {|x| [x.name,x.id]}
    @courses = Course.all.collect {|x| [x.name,x.id]}
    @rooms = Room.all.collect {|x| [x.name,x.id]}

  end

  # POST /attendences
  # POST /attendences.xml
  def create
    @attendence = Attendence.new(params[:attendence])

    respond_to do |format|
      if @attendence.save
        format.html { redirect_to :action=>'index', :notice => 'Attendence was successfully created.' }
        format.xml  { render :xml => @attendence, :status => :created, :location => @attendence }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @attendence.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /attendences/1
  # PUT /attendences/1.xml
  def update
    @attendence = Attendence.find(params[:id])

    respond_to do |format|
      if @attendence.update_attributes(params[:attendence])
        format.html { redirect_to :action=>'index', :notice => 'Attendence was successfully updated.' }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @attendence.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /attendences/1
  # DELETE /attendences/1.xml
  def destroy
    @attendence = Attendence.find(params[:id])
    @attendence.destroy

    respond_to do |format|
      format.html { redirect_to(:action => 'index') }
      format.xml  { head :ok }
    end
  end
end
